package com.cheer.ba.utils;

import java.math.RoundingMode;
import java.text.DecimalFormat;

/**
 * Created by JS01 on 2016/7/25.
 */
public class MoneyUtils {

    public static String formatMoney(double money) {
        DecimalFormat format = new DecimalFormat("0.00");
        format.setRoundingMode(RoundingMode.HALF_UP);
        String str = format.format(money);
        return str;
    }

    public static double getDouble(double num) {
        DecimalFormat format = new DecimalFormat("0.00");
        format.setRoundingMode(RoundingMode.HALF_UP);
        double newNum = 0.00d;
        newNum = Double.parseDouble(format.format(num));
        return newNum;
    }

    public static double getDouble(String numStr) {
        DecimalFormat format = new DecimalFormat("0.00");
        format.setRoundingMode(RoundingMode.HALF_UP);
        double num = 0.00d;
        try {
            double d = Double.parseDouble(numStr);
            String str = format.format(d);
            num = Double.parseDouble(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }
}
